package com.lib.base.ui.dialog

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import android.view.*
import com.lib.base.R


import com.lib.base.util.LogUtil


/**
 * @date  2019/5/31 0031.
 * @author Administrator
 */
internal open class BaseDialogNoBinding(
    context: Context,
    var windowWidth: Int = WindowManager.LayoutParams.MATCH_PARENT,
    var windowHeight: Int = WindowManager.LayoutParams.WRAP_CONTENT,
    var windowGravity: Int = Gravity.CENTER,
    var windowDimAmount: Float = 0.6f,
    var windowAnimations: Int = R.style.dialogAnim,
    var useDefaultPadding: Boolean = false,
    var paddingLeft: Int = 0,
    var paddingTop: Int = 0,
    var paddingRight: Int = 0,
    var paddingBottom: Int = 0,
) : Dialog(context, R.style.BaseDialog) {

    private var view: View? = null

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        //DESC:itz:2023/2/22 13:34: 去除dialog动画，加上动画会有bug
        //window?.setWindowAnimations(windowAnimations)
        if (!useDefaultPadding) {
            window?.decorView?.setPadding(paddingLeft, paddingTop, paddingRight, paddingBottom)
        }
        window?.attributes = window?.attributes?.apply {
            width = windowWidth
            height = windowHeight
            dimAmount = windowDimAmount
            gravity = windowGravity
        }
        if (view != null) {
            setContentView(view!!)
        }
    }

    fun setView(view: View) {
        this.view = view
    }

    override fun onDetachedFromWindow() {
        super.onDetachedFromWindow()
        LogUtil.d("Dialog","onDetachedFromWindow")
    }

    override fun dismiss() {
        super.dismiss()
        LogUtil.d("Dialog","dismiss")
    }

}